﻿using NFine.Domain.Entity.BusinessManage;
using NFine.Domain.IRepository.BusinessManage;
using NFine.Repository.BusinessManage;
using NFine.Code;
using System.Collections.Generic;
using System.Linq;

namespace NFine.Application.BusinessManage
{
    public class D_NewsListApp
    {
        private ID_NewsListRepository service = new D_NewsListRepository();

        public List<D_NewsListEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<D_NewsListEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_Title.Contains(keyword));
                expression = expression.Or(t => t.F_Sketch.Contains(keyword));
                expression = expression.Or(t => t.F_Content.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public List<D_NewsListEntity> GetList()
        {
            return service.IQueryable().ToList();
        }

        public List<D_NewsListEntity> GetGrid(string keyword)
        {
            var expression = ExtLinq.True<D_NewsListEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_Title.Contains(keyword));
            }
            return service.FindList(expression);
        }
        public D_NewsListEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }
        public void SubmitForm(D_NewsListEntity newsListEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                newsListEntity.Modify(keyValue);
                service.Update(newsListEntity);
            }
            else
            {
                newsListEntity.Create();
                service.Insert(newsListEntity);
            }
        }
    }
}
